class Anima{
    String name;
    int age;
    String color;
    public Anima(String name,int age){
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println(name + "吃东西");
    }
}
class Dog extends Anima{
    public Dog(String name,int age){
        super(name,age);
    }
    public void eat(){
        System.out.println(name + "吃狗粮");
    }
    public void bark(){
        System.out.println(name + "汪汪汪");
    }
}
class Bird extends Anima{
    public Bird(String name,int age){
        super(name,age);
    }
    public void fly(){
        System.out.println(name + "正在飞");
    }

    @Override
    public void eat() {
        System.out.println(this.name+ "吃谷子");
    }
}
public class test1 {
    public static void main(String[] args) {
        //向上转型，父类引用指向子类对象
        Anima anima1 = new Bird("小鸟1",3);
        //向下转型，父类引用转为子类引用
        //由于父类引用实际指向的就是一个子类bird，所以能成功
        Bird bird = (Bird)anima1;
        //向上转型，父类引用指向子类对象
        Anima anima2 = new Bird("小鸟2",4);
        //错误的向下转型，虽然父类转换为了子类引用
        //但是父类引用实际上指向的是Bird类而不是Dog类，所以会报错
        //Dog dog1 = (Dog)anima2;
        Anima anima = new Bird("臭鸟",5);
        anima.eat();
        Bird bird1 = new Bird("臭鸟2",4);
        animaEat(bird1);
    }
    public static void animaEat(Anima anima){
        anima.eat();
    }
}
